<?php
session_start();
if (!isset($_SESSION['username'])) {
    $_SESSION['username'] = 'Гость';
    $_SESSION['role'] = 'guest';
}
?>

<!DOCTYPE html>
<html lang="ru">
<head>
    <meta charset="UTF-8">
    <title>ESHOP | Главная страница</title>
    <link rel="icon" type="image/png" sizes="32x32" href="/images/other/r-favicon-32x32.png">
    <link rel="stylesheet" href="/css/main_style.css">
    <link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.0.0-beta3/css/all.min.css">
    <link rel="stylesheet" href="https://code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
    <script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>
    <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.min.js"></script>
    <script type="text/javascript">
        var isLoggedIn = <?php echo json_encode(isset($_SESSION['username']) && $_SESSION['username'] !== 'Гость'); ?>;
        var globalUserId = <?php echo isset($_SESSION['user_id']) ? htmlspecialchars($_SESSION['user_id']) : '0'; ?>;
        document.addEventListener('DOMContentLoaded', function () {
            console.log(typeof globalUserId !== 'undefined');
            loadUserCart();
            loadCategories();
            loadProducts();
            initializeSlider();
        });
    </script>
    <script src="/scripts/catalog_scripts.js"></script>
</head>
<body>
    <div class="container">
        <header>
            <div class="header-top">
                <div class="header-title">
                    <h1><i>ESHOP</i></h1>
                    <h3>Магазин бытовой электроники</h3>
                </div>
                <div class="header-icons">
                    <div class="user-info">
                        <span><?php echo htmlspecialchars($_SESSION['username']); ?></span>
                        <div class="icon-container" onclick="openProfile()">
                            <i class="fas fa-user"></i>
                        </div>
                        <?php if ($_SESSION['role'] === 'admin'): ?>
                            <a href="admin_panel.php" class="icon-container" title="Администраторская панель">
                                <i class="fas fa-tools"></i>
                            </a>
                        <?php endif; ?>
                        <div class="icon-container" onclick="openCart()">
                            <i class="fas fa-shopping-cart"></i>
                            <span id="cartIndicator" class="cart-indicator"></span>
                        </div>
                    </div>
                </div>
            </div>
            <div class="search-container">
                <input type="text" id="searchInput" class="search-input" placeholder="Поиск товаров..." oninput="searchProducts()">
                <select id="categorySelect" class="category-select" onchange="filterByCategory()">
                    <option value="">Все категории</option>
                </select>
                <label class="switch">
                    <input type="checkbox" id="advancedFilterCheckbox" onchange="toggleAdvancedFilter()">
                    <span class="slider round"></span>
                </label>
                <label for="advancedFilterCheckbox" class="advanced-filter-label">Расширенный фильтр</label>
            </div>
        </header>
        <section id="slider">
            <div class="slider-controls">
                <button id="prevButton"><i class="fas fa-chevron-left"></i></button>
                <button id="nextButton"><i class="fas fa-chevron-right"></i></button>
            </div>
        </section>

        <section id="productList"></section>

        <div id="advancedFilterSidebar" class="sidebar">
            <span class="close-sidebar" onclick="toggleAdvancedFilter()">&times;</span>
        </div>

        <div id="productModal" class="modal">
            <div class="modal-content">
                <span class="close-button">&times;</span>
                <div id="modalProductContent" class="modal-product-content">
                </div>
            </div>
        </div>
        
        <footer>
            <div class="footer-container">
                <div class="footer-info">
                    <span>Контакты:</span>
                    <span>пер.Измаильский , 41, г. Ростов-на-Дону, Россия</span>
                    <span>+7 (988) 541-12-09</span>
                    <span>info@eshop.ru</span>
                    <a href="call_specialist.php">Вызвать специалиста по установке техники</a> <!-- Добавленная ссылка -->
                </div>
            </div>
        </footer>
    </div>
    <div id="sidebarHandle" class="sidebar-handle">
        <i class="fas fa-arrow-left"></i>
    </div>
</body>
</html>
